package com.greyu.ysj.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.greyu.ysj.config.ResultStatus;
import com.greyu.ysj.entity.TableBlackList;
import com.greyu.ysj.entity.TableBlackListExample;
import com.greyu.ysj.mapper.TableBlackListMapper;
import com.greyu.ysj.model.ResultModel;
import com.greyu.ysj.service.TableBlackListServer;
@Service
public class TableBlackListServerImpl implements TableBlackListServer {
	
	@Autowired
	TableBlackListMapper tableBlackListMapper;
	@Override
	public ResultModel save(TableBlackList tableBlackList) {
		// TODO Auto-generated method stub
		if (null == tableBlackList.getAddress())
		{
			return ResultModel.error(ResultStatus.DATA_NOT_NULL);
    	}
				//insert
		this.tableBlackListMapper.insert(tableBlackList);
		return ResultModel.ok(tableBlackList);
	}

	@Override
	public boolean isAddressIsExit(String address) {
		// TODO Auto-generated method stub
		TableBlackListExample tableBlackListExample = new TableBlackListExample();
		TableBlackListExample.Criteria criteria = tableBlackListExample.createCriteria();
        criteria.andAddressEqualTo(address);
        List<TableBlackList> tableBlackLists = this.tableBlackListMapper.selectByExample(tableBlackListExample);
        
        TableBlackList tmpBlackList;
        try {
        	 tmpBlackList = tableBlackLists.get(0);
        } catch (Exception e) {
            return false;
        }
		return true;
	}

}
